********************************************************************************
*DYNAMIC IMPACTS OF PRICING GROUNDWATER
*Bruno, Jessoe, Hanemann in JAERE
********************************************************************************
clear all
capture log close
set more off

*SELECT OUTPUT DATE
global outputdate = "20231125"		 

*SET DIRECTORY
cd  "D:\Ellen\Dropbox\Pajaro_AgInnovation" 

log using "D:\Ellen\Dropbox\Pajaro_AgInnovation\Submission\JAERE\Replication_Code\Log\DinD_annual_well_log.log", replace

*SELECT DATASET
global dataset 2	 
global quarterly "Data\Well_Clean_20230627.dta"
global yearrun "Data\Well_clean_yearrun_20230627.dta"

if $dataset == 1 use $quarterly, clear
if $dataset == 2 use $yearrun, clear

********************************************************************************
*TABLE 9: ANNUAL EXTRACTION DIFF IN DIFF AT WELL LEVEL
********************************************************************************
*Balance the panel
bysort sitenum: gen ntime = [_N]
sum ntime
keep if ntime==`r(max)'

*Drop 2010
drop if year_run==5 
drop if year_run >10

eststo clear
*Column 1: No FE
eststo: reg extraction treatment post inside if year_run <11, cluster(parcelnum)
	estadd local wellFE " "
	estadd local timeFE " "
	estadd local controls " "
*Column 2: Add well FE
eststo: xtreg extraction treatment post if year_run <11, fe cluster(parcelnum) 
	estadd local wellFE " \checkmark  "
	estadd local timeFE " "
	estadd local controls " "
*Column 3: Add year FE
eststo: xtreg extraction treatment i.year_run if year_run <11, fe cluster(parcelnum)
	estadd local wellFE " \checkmark  "
	estadd local timeFE " \checkmark  "
	estadd local controls " "
*Column 4: Add county-year FE
eststo: xtreg extraction treatment i.year_run#i.county if year_run <11, fe cluster(parcelnum)
	estadd local wellFE " \checkmark  "
	estadd local timeFE " "
	estadd local controls " \checkmark  "
esttab using "Tables\Extraction_DinD_well_$outputdate.tex", label replace ///
	se star(* .10 ** .05 *** .01) ///
	addnote(Table reports results from diff-in-diff regression. Standard errors are clustered at the parcel level.) ///
	keep(_cons post treatment inside) ///
	scalars("wellFE Parcel FE" "timeFE Year FE" "controls County-Year FE") ///
	cells(b(star fmt(2)) se(par fmt(2)))
eststo clear

log close
